home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10833 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: void test(...)
  5. Date: 20 Mar 1996 09:23:18 GMT
  6. Organization: systems hk
  7. Message-ID: <4ioiq6$6nd@nadine.teleport.com>
  8. References: <4if00v$hdk@news.NetVision.net.il>
  9. NNTP-Posting-Host: ip-pdx03-24.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. nir@netvision.net.il (Nir Sofer) wrote:
  16. >I know that i can create in C a function with  variable number of arguments.
  17. >
  18. >void test(...)
  19. >{
  20. >}
  21. >
  22. >But i can i use these arguments ???
  23. >
  24. >Nir Sofer
  25. >nir@netvision.net.il
  26. >
  27. Nir,
  28.  
  29. I use the following to output to a file without having to open
  30. the file each time.  It is basically like 'printf' (which has
  31. variable arguments) with the first argument the name of the
  32. file I am writing to.
  33.  
  34. /*----------------------------------------------------------------------+
  35. |  FLP -    output log messages.  Opens/closes the logfile before/after
  36. |        each write
  37. +----------------------------------------------------------------------*/
  38. int    FLP ( char *file, char *fmt, ... )
  39. {
  40.   FILE        *strm;
  41.   va_list    argptr;
  42.   int        cnt;
  43.  
  44.   strm = fopen( file,"a+" );
  45.   if( !strm )
  46.     strm = fopen( file,"w" );
  47.   if( !strm )
  48.     return( 0 );
  49.   va_start( argptr,fmt );
  50.   cnt = vfprintf( strm,fmt,argptr );
  51.   va_end( argptr );
  52.  
  53.   fclose( strm );
  54.  
  55.   return( cnt );
  56. }
  57.  
  58.  
  59.